package com.bjshiwei.zhengu.requestInfo;

import android.app.Activity;

import com.android.volley.Response;

import org.json.JSONException;
import org.json.JSONObject;

/**
  * @desc请求处理基类
  * @author sanjin
  * @time 2016/9/23 0023 下午 1:11
  */
public abstract class RequestListenerInfo implements Response.Listener {
    public Activity mActivity;

    public RequestListenerInfo(Activity mActivity) {
        this.mActivity = mActivity;
    }

    @Override
    public void onResponse(Object o) {
        JSONObject jsonObject = null;
        String jsonStr =  o.toString();
        try {
            /*if(jsonStr != null && jsonStr.startsWith("\ufeff"))
            {
                jsonStr =  jsonStr.substring(1);
            }*/
            if (jsonStr != null) {
                jsonStr = jsonStr.replaceAll("\ufeff", "");
            }
            jsonObject = new JSONObject(jsonStr);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        onAnalysis(o,jsonObject, true);
/*        if (null != o) {
            int code = -1;
            String msg = "";
            try {
                code = jsonObject.getInt("code");
                msg = jsonObject.getString("msg");

            } catch (JSONException e) {
                e.printStackTrace();
            }*/
          /*  if (0 != code) {
                if (code == 2) {
                    if (null != mActivity) {
                        PrefUtil.getInstance(mActivity).removeUserInfo();
//                        ToastUtil.showShortToast(mActivity, R.string.you_have_been_kick_out_please_relog);
                        mActivity.finish();
//                        mActivity.startActivity(new Intent(mActivity, LogingActivity.class));
                    }
                } else {
                    if (null != mActivity) {
                        ToastUtil.showShortToast(mActivity, msg);
                    }
                }
                onAnalysis(jsonObject, false);
            } else {
                onAnalysis(jsonObject, true);
            }
        }*/
    }

    protected abstract void onAnalysis(Object o, JSONObject jsonObject, boolean success);
}